package nz.ac.massey.cs.se400_2013.ass3;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

public class Student implements Visitable {
	private String name = "";
	private String firstName = "";
	private Date dob = new Date();
	private Address address = new Address();
	private Collection<Paper> papers = new HashSet<Paper>();
	private Course course = null;
	
	@Override
	public void accepts(Visitor visitor) {
		address.accepts(visitor);
		visitor.visit(this);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public Date getDob() {
		return dob;
	}

	public void setDob(Date dob) {
		this.dob = dob;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Collection<Paper> getPapers() {
		return papers;
	}
	
	public void addPaper(Paper paper){
		if(this.papers.add(paper)){
			paper.addStudent(this);
		}
	}
	
	public void removePaper(Paper paper){
		if(this.papers.remove(paper)){
			paper.removeStudent(this);
		}
	}

	public void setPapers(Collection<Paper> papers) {
		this.papers = papers;
	}

	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", firstName=" + firstName
				+ ", course=" + course + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((dob == null) ? 0 : dob.hashCode());
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (dob == null) {
			if (other.dob != null)
				return false;
		} else if (!dob.equals(other.dob))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
